package jrobutt;

import java.awt.*;

public class GameObject implements Updatable, Renderable
{
    public float x;
    public float y;
    public float xspeed;
    public float yspeed;
    
    public GameSprite sprite;
    
    public float getWidth ()
    {
        return sprite == null ? 0.0f : sprite.width;
    }
    public float getHeight ()
    {
        return sprite == null ? 0.0f : sprite.height;
    }
    
    public GameObject (float x, float y, GameSprite sprite)
    {
        this.x = x;
        this.y = y;
        
        this.xspeed = 0.0f;
        this.yspeed = 0.0f;
        
        this.sprite = sprite;
    }
    public GameObject (float x, float y)
    {
        this(x, y, null);
    }
    
    protected void move ()
    {
        x += xspeed;
        y += yspeed;
    }
    
    public void update ()
    {
        this.move();
    }
    
    public void render (Graphics2D g)
    {
        if (sprite != null)
        {
            sprite.renderAt(g, x, y);
        }
    }
}
